<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
	</head>
	<body>
        <img src='one.png' />
	</body>
	<script type="text/javascript">

        // function CodingMan(name){

        //     function SayName(name){
        //         this.name = name;
        //         // console.log(`Hi! This is ${this.name}!`)
        //     }

        //     SayName.prototype.sleep = function(time){
        //         this.t = time*1000;
        //         var self = this;
                
        //         setTimeout(function(){
        //             console.log(`wake up after ${time}`)
        //             self.next()
        //         },this.t)

        //         return this;
        //     }

        //     SayName.prototype.next = function(){
        //         console.log(`Hi! This is ${this.name}!`)
        //     }

        //     SayName.prototype.eat = function(drink){
                
        //         setTimeout(function(){
        //             console.log(`Eat ${drink}`)
        //         },this.t)
        //     }

        //     return new SayName(name);
        // }
        
        // CodingMan('Peter').sleep(3).eat('dinner');


        // function CodingMan(name){
            
        //     function Domethings(name){
        //         this.con = [];
        //         this.name = name;
        //         console.log(`Hi! this is Peter`)
        //     }

        //     Domethings.prototype.sleep = function(time){
        //         this.con.push(`Wake up after ${time}`)
        //         setTimeout(()=>{
        //             this.con.forEach((item)=>{
        //                 console.log(item)
        //             })
        //         },time*1000)
        //         return this;
        //     }

        //     Domethings.prototype.eat = function(dinner){
        //         this.con.push(`Eat ${dinner}`)
        //     }

        //     return new Domethings(name);

        // }

        // CodingMan('Peter').sleep(3).eat('dinner')

        function CodingMan(name){
            function Domethings(name){
                this.name = name;
                this.ifFirst = false;
            }
            
            Domethings.prototype.consoleName=function(){
                console.log(`Hi ${name}`)
            }

            Domethings.prototype.sleep = function(time){
                let start = (new Date()).getTime();
                
                while ((new Date()).getTime() - start < time*1000) {
                    // continue
                }
                console.log(`waite after ${time}`)
                
                return this;
            }

            Domethings.prototype.eat = function(something){
                console.log(something)
                return this;
            }

            Domethings.prototype.sleepFirst = function(time){
                this.ifFirst = true;
                this.sleep(time);
                
                return this;
            }
            
            return new Domethings(name)
        }     

        CodingMan('Peter').sleep(3).eat('drink')

	</script>
</html>
